﻿<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/component/commonTagLib.jsp"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>
<title></title>
<%@ include file="/WEB-INF/component/commonCSS.jsp"%>
<style type="text/css">
        
        .box-body{
                margin-top:-10px;
         } 
    </style>
</head>
<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">
    <section class="content-header">
        <h1><spring:message code="message.lable.drugcatalogSTDsee"/></h1>
        <ol class="breadcrumb">
            <li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i><spring:message code="message.lable.first"/></a></li>
            <li class="active"><a href="#"><spring:message code="message.lable.StdManage"/></a></li>
            <li class="active"><a href="#"><spring:message code="message.lable.drugcatalogStd"/></a></li>
        </ol>
    </section>
    <section class="content">
     <form id="form" method="post" class="form-horizontal"> 
        <div class=" box box-success">
            <div class="box-body">
                <div class="input">
                <div class="textalign1"><spring:message code="message.listForm.yaoPinMuLuMingCheng"/>：</div>
                    <div class="boxinput">
                        <input type="text" class="textinput" id="drugcatalogName" name="drugcatalogName" placeholder="<spring:message code="message.listForm.yaoPinMuLuMingCheng"/>"/>
                    </div>
                    <div class="textalign"><spring:message code="message.listForm.yaoPinMuLuBianMa"/>：</div>
                    <div class="boxinput">
                        <input type="text" class="textinput" id="drugcatalogCode" name="drugcatalogCode" placeholder="<spring:message code="message.listForm.yaoPinMuLuBianMa"/>"/>
                    </div>
                    
                    <div class="textalign"><spring:message code="message.listForm.QiYongRiQi"/>：</div>
                    <div class="boxinput"> 
                       <table style="width:100%">
                                <tr>
                                    <td style="width:50%">
                                        <input class="textinput" type="text" name="startTime" id="startTime"   placeholder="yyyy-MM-dd"
                                  onFocus="var endDate=$dp.$('endTime');WdatePicker({maxDate:'#F{$dp.$D(\'endTime\')}'})" />
                                    </td>
                                    <td>&nbsp;-&nbsp;</td>
                                    <td style="width:50%">
                                        <input class="textinput" type="text" name="endTime" id="endTime"   placeholder="yyyy-MM-dd"
                                    onFocus="WdatePicker({minDate:'#F{$dp.$D(\'startTime\')}'})" />
                                    </td>
                                </tr>
                             </table>
                       </div>
                   </div> 
                   <div class="input">
                       <div class="textalign1"><spring:message code="message.lable.status"/>：</div>
                       <div class="boxinput">
                           <select class="textinput" name="status" id="status">
                            <option value=""><spring:message code="message.select.option"/></option>
                            <option value="1"><spring:message code="message.button.start"/></option>
                            <option value="0"><spring:message code="message.button.stop"/></option>
                        </select>
                       </div>
                       <div class="textalign" >
                            <input id="selectCata" type="button" id="selectDicCompType" onclick="likeQuery();" class="btn btn-success btn-sm" value="<spring:message code="message.button.seachSpacing"/>">
                       </div> 
                   </div>
            </div>
         </div>
        </form>
        <table class="jqgrid" id="gridlist"></table>
        <div id="gridpage"></div>
        <div class=" box box-warning bottongroup">
            <ms:btn url="/stdDrugcatalog/add.html"><label id="addNew" class="btn btn-default btn-sm"><spring:message code="message.button.addSpacing"/></label></ms:btn>
            <ms:btn url="/stdDrugcatalog/enable.html"><label id="allStart" class="btn btn-default btn-sm" onclick="groupUpdate(1);"><spring:message code="message.button.startSpacing"/></label></ms:btn>
            <ms:btn url="/stdDrugcatalog/disable.html"><label id="allDelete" class="btn btn-default btn-sm" onclick="groupUpdate(0);"><spring:message code="message.button.stopSpacing"/></label></ms:btn>
        </div>
        <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header bg-primary">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h5 class="modal-title" id="exampleModalLabel"><spring:message code="message.lable.drugcatalogSTDadd"/></h5>
                    </div>
                    <form action="" id="form2">
                    <div class="modal-body">
                        <div class="form-group form-group-xs">
                            <label for="recipient-name" class="control-label"><span style="color:red">* </span><spring:message code="message.listForm.yaoPinMuLuMingCheng"/>：</label>
                            <div class="">
                                <input type="text" class="form-control" id="drugcataName" name="drugcatalogName" placeholder="<spring:message code="message.listForm.yaoPinMuLuMingCheng"/>">
                            </div>
                        </div>
                            <div class="form-group form-group-xs">
                        <label><span style="color:red">* </span><spring:message code="message.listForm.QiYongRiQi"/>：</label>
                            <div class="input-group">
                                  <input class="form-control" type="text" id="TimeBegin"   name="startTimeStr"   placeholder="yyyy-MM-dd"
                                  onFocus="var endDate=$dp.$('TimeEnd');WdatePicker({maxDate:'#F{$dp.$D(\'TimeEnd\')}'})" 
                                  />
                            </div>
                        </div>
                            <div class="form-group form-group-xs">
                        <label><span style="color:red">* </span><spring:message code="message.listForm.tingYongRiQi"/>：</label>
                            <div class="input-group">
                                 <input class="form-control" type="text"  id="TimeEnd"  name="endTimeStr"   placeholder="yyyy-MM-dd"
                                    onFocus="WdatePicker({minDate:'#F{$dp.$D(\'TimeBegin\')}'})" 
                                    />
                            </div>
                        </div>
                        
                        <div class="form-group form-group-xs">
                            <label for="txtDrugForm"><span style="color:red">* </span><spring:message code="message.listForm.leiXing"/>：</label>
                            <select class="form-control"  id="attribute" name="attributeStr">
                                <option value=""><spring:message code="message.select.option"/></option>
                                <option value="0"><spring:message code="message.listForm.guoJiaMuLu"/></option>
                                <option value="1"><spring:message code="message.listForm.shengZengBuMuLu"/></option>
                            </select>
                       </div>
                       <input type="text" id="drugcatalogId" name="drugcatalogIdStr" style="display:none" />
                        <div id="twoSpec" style="display:none"></div>
                    </div>
                    </form>
                    <div class="box-footer text-center">
                     <input hidden="true" id="spid"/>
                       <input hidden="true" id="spfatherid"/>
                        <button type="button" class="btn btn-primary btn-sm" id="submitDicCompType" onclick="save();"><spring:message code="message.button.saveSpacing"/></button>
                        <button type="button" class="btn btn-danger btn-sm" data-dismiss="modal" id="closeDicCompType"><spring:message code="message.button.closeSpacing"/></button>
                    </div>
                </div>
            </div>
        </div>
    </section>
    <%@ include file="/WEB-INF/component/commonJS.jsp"%>
    <script type="text/javascript">
    //绑定回车
    $('#drugcatalogCode,#drugcatalogName,#startTime,#endTime,#status').bind('keydown', function(event) {
        if (event.keyCode == "13") {        //13 位电脑上回车键的位置代码
            $('#selectCata').click();
        }
    }); 
  
    $("#drugcatalogName").focus();//加载页面光标在第一个查询框内
        $(function () {//新增
            $("#gridlist").jqGrid({
                url: "getStdDrugcatalogData.html",
                mtype: "POST",
                datatype: "json",
                autowidth: true,
                height: 255,                    
                colNames: ['<spring:message code="message.jqGrid.cz"/>',
                           '<spring:message code="message.listForm.yaoPinMuLu"/>id',
                           '<spring:message code="message.listForm.yaoPinMuLuBianMa"/>',
                           '<spring:message code="message.listForm.yaoPinMuLuMingCheng"/>',
                           '<spring:message code="message.listForm.QiYongRiQi"/>', 
                           '<spring:message code="message.listForm.tingYongRiQi"/>',
                           '<spring:message code="message.listForm.leiXing"/>',
                           '<spring:message code="message.lable.status"/>'
                           ],
                colModel: [
                        { name: 'operate', width: "110", align:"center",sortable: false,
                            formatter : function(val, opts, rowdata) {
                                var str = "";
                                str += "<ms:btn url='/stdDrugcatalog/edit.html'><a href=\"javascript:edit('"+rowdata.drugcatalogName+"','"+new Date(rowdata.startTime).format("yyyy-MM-dd")+"','"+new Date(rowdata.endTime).format("yyyy-MM-dd")+"','"+rowdata.attribute+"','"+rowdata.drugcatalogId+"');\" style='background:url(${ctx}/lib/img/icon/icon.png) no-repeat 0px 0px' class='opIcon' title='<spring:message code="message.jqGrid.cz.bianJi"/>'></a></ms:btn>";
                                str +="<ms:btn url='/stdDrugcatalog/toStdDrugcatalogDetailInfo.html'><a href='${ctx}/stdDrugcatalog/toStdDrugcatalogDetailInfo.html?drugcatalogId="+rowdata.drugcatalogId+"&drugcatalogName="+rowdata.drugcatalogName+"' style='background:url(${ctx}/lib/img/icon/icon.png) no-repeat -100px 0px' class='opIcon' title='<spring:message code="message.jqGrid.cz.xiangQing"/>'></a></ms:btn>";
                                str += "<ms:btn url='/stdDrugcatalog/toStdDrugcatalogDetailInfoAdd.html'><a   href='${ctx}/stdDrugcatalog/toStdDrugcatalogDetailInfoAdd.html?drugcatalogId="+rowdata.drugcatalogId+"&drugcatalogName="+rowdata.drugcatalogName+"' style='background:url(${ctx}/lib/img/icon/icon.png) no-repeat -180px 0px' class='opIcon' title='<spring:message code="message.button.addDetail"/>'></a></ms:btn>";
                                str +=  "<ms:btn url='/stdDrugcatalog/toStdDrugcatalogLogDetailInfo.html'><a  href='${ctx}/stdDrugcatalog/toStdDrugcatalogLogDetailInfo.html?drugcatalogId="+rowdata.drugcatalogId+"&drugcatalogCode="+rowdata.drugcatalogCode+"&drugcatalogName="+rowdata.drugcatalogName+"&code="+rowdata.drugcatalogCode+"&name="+rowdata.drugcatalogName+"' style='background:url(${ctx}/lib/img/icon/icon.png) no-repeat -120px 0px' class='opIcon' title='<spring:message code="message.jqGrid.cz.weiHuJiLu"/>'></a></ms:btn>";
                                return str;
                        }
                        },
                        { name: 'drugcatalogId',hidden:true, width: "0",align: 'center',sortable: false},       
                        { name: 'drugcatalogCode', width: "80",align: 'center',sortable: false},
                        { name: 'drugcatalogName', width: "180",align: 'center' ,sortable: false},
                        { name: 'startTime', width: "120",align: 'center',sortable: false,
                            formatter : function(val, opts, rowdata) {
                                return new Date(val).format("yyyy-MM-dd");
                            }
                        },
                        { name: 'endTime', width: "120", align: 'center',sortable: false,
                            formatter : function(val, opts, rowdata) {
                                return new Date(val).format("yyyy-MM-dd");
                            }
                        },
                    
                        { name: 'attribute', width: "80", align: 'center',sortable: false,
                            formatter : function(val, opts, rowdata) {
                                var temp='<spring:message code="message.listForm.qiTa"/>';
                                if(val == 0){temp = '<spring:message code="message.listForm.guoJiaMuLu"/>';}
                                else if (val == 1){ temp = '<spring:message code="message.listForm.shengZengBuMuLu"/>'; }
                                return temp;
                            }
                        },
                        { name: 'status', width: "60", align: 'center',sortable: false,
                            formatter : function(val,opts,row){
                                if(val==1){
                                    return "<spring:message code="message.button.start"></spring:message>";
                                }else if(val==0){
                                    return "<span class='red'><spring:message code="message.button.stop"></spring:message></span>";
                                }
                            }
                        }
                        
                ],
                rowNum: 20,
                rowList: [10, 20, 50,100],
                rownumbers: true,
                pager: "#gridpage",
                viewrecords: true,
                multiselect: true, //勾选框
                caption: "<spring:message code="message.list.drugcatalogStdlist"/>",
                gridComplete:function(){
                    autoRNWidth("gridlist");
                    selectByOneData("gridlist");
                },
                jsonReader: {
                    repeatitems: false,
                    id: "drugcatalogId"
                }
            });
            $("#gridlist").jqGrid('navGrid', '#gridpage', { add: false, edit: false, del: false, search: false, refresh: false });
            $(window).trigger("resize");
            //moreNoMore();
        });
        
        function likeQuery(page){
            var drugcatalogCode  = $.trim( $("#drugcatalogCode").val());
            var drugcatalogName = $.trim( $("#drugcatalogName").val());
            var startTime  = $.trim( $("#startTime").val());
            var endTime = $.trim( $("#endTime").val());
            var status = $("#status").val();
            $("#gridlist").jqGrid('setGridParam', { 
                mtype:"post",
                postData:{
                    "startTime":startTime,
                    "endTime":endTime,
                    "drugcatalogCode":drugcatalogCode,
                    "drugcatalogName":drugcatalogName,
                    "status":status
                },
                page : (page || 1)
           }).trigger("reloadGrid");
       }
        
         $('#addNew').click(function () {
             $('#drugcataName').val("");
             $('#TimeBegin').val("");
             $('#TimeEnd').val("");
             $('#attribute').val("");
             $('#drugcatalogId').val("");
             $('#exampleModalLabel').html("<spring:message code="message.lable.drugcatalogSTDadd"/>");
             $('#exampleModal').modal({
                 keyboard: true
             });
          
         });
         
          function validate() {
            var drugcataName = $.trim($("#drugcataName").val());
            if (drugcataName == null || drugcataName == "") {
                $.alert("<spring:message code="message.yanZheng.qingShuRu"/><spring:message code="message.listForm.yaoPinMuLuMingCheng"/>！",  "warn");
                return false;
            }
            if (drugcataName.length>170) {
                $.alert("<spring:message code="message.listForm.yaoPinMuLuMingCheng"/><spring:message code="message.info.zuiDaChangDu"/>170<spring:message code="message.info.geZiFu"/>！",  "warn");
                return false;
            }
            
            var createTimeBegin = $.trim($("#TimeBegin").val());
            if (createTimeBegin == null || createTimeBegin == "") {
                $.alert("<spring:message code="message.select.option"/><spring:message code="message.listForm.QiYongRiQi"/>！",  "warn");
                return false;
            }
            
            var createTimeEnd = $.trim($("#TimeEnd").val());
            if (createTimeEnd == null || createTimeEnd == "") {
                $.alert("<spring:message code="message.select.option"/><spring:message code="message.listForm.tingYongRiQi"/>！",  "warn");
                return false;
            }
            
            var attribute = $.trim($("#attribute").val());
            if (attribute == null || attribute == "") {
                $.alert("<spring:message code="message.select.option"/><spring:message code="message.listForm.leiXing"/>！",  "warn");
                return false;
            }
            return true;
        }
            function save() {
                if(validate()){
                      $.HN.message.confirm('<spring:message code="message.HN.alert.OkSaveYESorNO"/>', '', '').on(function(e) {
                            if (e) {
                              var postData = formatForm("form2");
                              
                              var url = "${ctx}/stdDrugcatalog/add.html";
                              if(drugcatalogId !=null && drugcatalogId != ""){     
                            	  url = "${ctx}/stdDrugcatalog/edit.html";     
                              }
                              $.post(url, postData, function(result) {
                                  if (result.success) {
                                	  if(drugcatalogId !=null && drugcatalogId != ""){
                                		  top.$.alert("<spring:message code='message.HN.alert.baoCunCheng'/>", "success");
                                      }else{
                                    	  top.$.alert("为您新增一条编码为"+result.msg+"的药品目录", "success");
                                      }
                                      likeQuery($("#gridlist").getGridParam("page"));
                                      $('#exampleModal').modal('hide');
                                  } else {
                                     top.$.alert("<spring:message code='message.HN.alert.baoCunBai'/>",  'error');
                                  }
                              }, "json");
                            }
                        });
                }
            }
         function edit(drugcatalogName,startTime,endTime,attribute,drugcatalogId){
             $('#drugcataName').val(drugcatalogName);
             $('#TimeBegin').val(startTime);
             $('#TimeEnd').val(endTime);
             $('#attribute').val(attribute);
             $('#drugcatalogId').val(drugcatalogId);
             $('#exampleModalLabel').html("<spring:message code="message.lable.drugcatalogSTDedit"/>");
             $('#exampleModal').modal({
                 keyboard: true
             })
         }
        
            function groupUpdate(status) {
                var msg = "<spring:message code="message.button.stop"/>";
                var url = "${ctx}/stdDrugcatalog/enable.html"; 
                if (status == 1) {
                    var msg = "<spring:message code="message.button.start"/>";
                    url = "${ctx}/stdDrugcatalog/disable.html"; 
                }
                
                var infos = batchSwitchStatus("gridlist","drugcatalogName","status",msg,"<spring:message code="message.listForm.yaoPinMuLu"/>");
                if (infos.length <= 1) {
                    return;
                }
                
                  $.HN.message.confirm('<spring:message code='message.button.confirm' />'+msg+'<spring:message code="message.lable.yiXia"/>'+infos[0].split(",").length+'<spring:message code="message.lable.tiao"/><spring:message code="message.listForm.yaoPinMuLu"/><spring:message code="message.lable.ma"/><br/>'+infos[1].replace(/\,/g,"<br/>"), '', '').on(function (e) {
                        if (e) {
                            $.ajax({
                                url:url,//action地址
                                data: { state:status,param:infos[0] },//传值
                                type: "post",//执行方式get or post 默认以post方式执行
                                dataType:"json",
                                success: function (result) {//执行成功后 提示
                                    if (result.success){
                                        top.$.HN.message.alert("<spring:message code='message.HN.alert.chengGong'/>"+msg+infos[0].split(",").length+"<spring:message code='message.lable.tiao'/><spring:message code='message.listForm.yaoPinMuLu'/><spring:message code='message.yanZheng.ganTanHao'/>","", "success");
                                       likeQuery($("#gridlist").getGridParam("page"));
                                   } else {
                                       top.$.HN.message.alert("<spring:message code='message.HN.alert.fail' />！", "","error");
                                   } 
                                }
                            });
                        }
                    });
                
            }
    </script>
</body>
</html>